package com.yuzhihao.writejvm.constant;

import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.format.PrintFormat;
import com.yuzhihao.writejvm.read.Parse;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Map;

/**
 *
 * The CONSTANT_Integer_info Structure
 *
 * @author yzh
 * @since  2021年12月01日19:08:21
 */

@Data
@Log4j2
@EqualsAndHashCode(callSuper = true)
public class ConstantIntegerInfo extends ConstantPool{

    private int bytes_u4 = 4;

    private int bytes;

    public ConstantIntegerInfo(Map<String,ConstantPool> pools) {
        super(pools);
        super.name = "Integer";
    }

    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            this.bytes = Parse.byteToInt(bytes_u4, dis);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }

    @Override
    public String print() {
        return PrintFormat.MEMPTY+String.valueOf(bytes);
    }

}
